|
|
|
| Creating a Pop-up Menu 1. On the frmMain form, add a top-level menu called mnuEmployee. 2. Set the Visible property on the mnuEmployee menu to False. .3. Add &New, &Save, &Delete, and &Close menus under this menu. .4. Go to the Employee Information form and select the Form_MouseUp() event. .5. Add the following code: | | Private Sub Form_MouseUp(Button As Integer, _
Shift As Integer, _
X As Single, _
Y As Single)
If Button = vbRightButton Then PopupMenu frmMain.mnuPopEmp End If
End Sub |  | In this code, you check to see whether the button pressed is the right mouse button by comparing the argument passed to the MouseUp event against the constant vbRightButton. If they are equal, you invoke the PopupMenu method and pass it the name of a menu. Because youre on the Employee Information form, you need to preface the name of the menu with the MDI form name, frmMain. Now you can run this project and right-click over the Employee Information form to have this pop-up menu displayed. One thing to notice is that if you position your mouse over a text box, label, or any other control, the code will not fire. Thats because youre only trapping the MouseDown event for the form. If you want to have the pop-up menu appear over other controls, you need to duplicate this code for every control. |
|
|
|